package cn.tedu.ivos01.vehicle.service.impl;

import cn.tedu.ivos01.vehicle.mapper.VehicleMapper;
import cn.tedu.ivos01.vehicle.pojo.dto.VehicleQuery;
import cn.tedu.ivos01.vehicle.pojo.dto.VehicleSaveParam;
import cn.tedu.ivos01.vehicle.pojo.entity.Vehicle;
import cn.tedu.ivos01.vehicle.pojo.vo.VehicleVO;
import cn.tedu.ivos01.vehicle.service.VehicleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Date;
import java.util.List;

@Slf4j
@Service
public class VehicleServiceImpl  implements VehicleService {
    @Autowired
    private VehicleMapper vehicleMapper;
    @Override
    public List<VehicleVO> selectVehicle(VehicleQuery vehicleQuery) {
        List<VehicleVO> list = vehicleMapper.selectVehicle(vehicleQuery);
        return list;
    }

    //保存车辆信息接口
    @Override
    public void saveVehicle(VehicleSaveParam vehicleSaveParam) {
        Vehicle vehicle = new Vehicle();
        BeanUtils.copyProperties(vehicleSaveParam,vehicle);
        if (vehicle.getId()==null){
            //新增车辆,车辆的状态设置为空闲
            vehicle.setStatus("1");
            vehicle.setCreateTime(new Date());
            vehicleMapper.insert(vehicle);
        }else {
            vehicle.setUpdateTime(new Date());
            vehicleMapper.update(vehicle);
        }
    }

    @Override
    public void deleteVehicle(Long id) {
        vehicleMapper.delete(id);
    }
}
